package powell.nflpredictionproject.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import powell.nflpredictionproject.display.MainPanel;
import powell.nflpredictionproject.display.UserPanel;

/*
 * This class uses statistics pulled from the database to predict the outcome
 * of the last five games of either the 2012 or 2013 season.
 */
public class PredictFiveWeeks
{

    UserPanel teams = new UserPanel();

    /*
     * This method gets statistics from the database and calculates the last
     * five games from either the 2012 or 2013 season.
     */
    public void calculateFiveWeekVictor(String awayTeam, String homeTeam)
    {
        try
        {
            //Away team variable declarations
            double awayTotalScore = 0;
            double awayFirstDown = 0;
            double awayThirdDown = 0;
            double awayRushAtt = 0;
            double awayRushYards = 0;
            double awayPassAtt = 0;
            double awayPassComp = 0;
            double awayPassYards = 0;
            double awayPassInt = 0;
            double awayFumbles = 0;
            double awaySackNum = 0;
            double awaySackYards = 0;
            double awayPenYards = 0;
            double awayTimeOfPoss = 0;
            double awayPuntAvg = 0;
            double awayOppScore = 0;
            double awayOppFirstDown = 0;
            double awayOppThirdDown = 0;
            double awayOppRushYards = 0;
            double awayOppPassYards = 0;
            //Home team variable declarations
            double homeTotalScore = 0;
            double homeFirstDown = 0;
            double homeThirdDown = 0;
            double homeRushAtt = 0;
            double homeRushYards = 0;
            double homePassAtt = 0;
            double homePassComp = 0;
            double homePassYards = 0;
            double homePassInt = 0;
            double homeFumbles = 0;
            double homeSackNum = 0;
            double homeSackYards = 0;
            double homePenYards = 0;
            double homeTimeOfPoss = 0;
            double homePuntAvg = 0;
            double homeOppScore = 0;
            double homeOppFirstDown = 0;
            double homeOppThirdDown = 0;
            double homeOppRushYards = 0;
            double homeOppPassYards = 0;
            double homeTeamTotalScore = 10.0;
            double awayTeamTotalScore = 0;

            if (MainPanel.getAnswer() == 0)
            {
                Connection conn = DriverManager.getConnection("jdbc:derby:NFLStatsDatabase");
                Statement stmt1 = conn.createStatement();
                ResultSet value1;

                /*
                 * Away Team
                 * 2012 Stats
                 * Calculations
                 */

                value1 = stmt1.executeQuery("Select AVG(SCOREOFF) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayTotalScore = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FirstDownOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayFirstDown = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select ThirdDownPCTOff from Stats2012 Where teamName = '" + awayTeam + "'");

                int count2 = 1;

                while (value1.next())
                {

                    awayThirdDown += Integer.parseInt(value1.getString(1).replaceAll("%", "").trim());

                    value1.next();

                    count2++;
                }

                awayThirdDown = awayThirdDown / count2;

                value1 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushAtt = value1.getInt(1);
                }

                value1.close();

                value1 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushAtt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassAttOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassAtt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassCompOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassComp = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassYDSOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassIntOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassInt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FumblesOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayFumbles = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SackNumOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awaySackNum = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SackYDSOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awaySackYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PenYDSOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPenYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select TimePOSSOff from Stats2012 Where teamName = '" + awayTeam + "'");

                int count4 = 1;

                while (value1.next())
                {

                    awayTimeOfPoss += Integer.parseInt(value1.getString(1).replaceAll(":", "").trim());

                    value1.next();

                    count4++;
                }

                awayTimeOfPoss = awayTimeOfPoss / count4;

                value1 = stmt1.executeQuery("Select AVG(PuntAVGOff) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPuntAvg = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SCOREDEF) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppScore = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FIRSTDOWNDEF) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppFirstDown = value1.getInt(1);
                }

                int count9 = 0;

                value1 = stmt1.executeQuery("Select ThirdDownPCTDEF from Stats2012 Where teamName = '" + awayTeam + "'");

                while (value1.next())
                {

                    awayOppThirdDown += Integer.parseInt(value1.getString(1).replaceAll("%", "").trim());

                    value1.next();

                    count9++;
                }

                awayOppThirdDown = awayOppThirdDown / count9;

                value1 = stmt1.executeQuery("Select AVG(RUSHYDSDEF) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PASSYDSDEF) from Stats2012 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppPassYards = value1.getInt(1);
                }

                value1.close();

                /*
                 * Home Team
                 * 2012 Stats
                 * Calculations
                 */

                ResultSet value2 = stmt1.executeQuery("Select AVG(SCOREOFF) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeTotalScore = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FirstDownOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeFirstDown = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select ThirdDownPCTOff from Stats2012 Where teamName = '" + homeTeam + "'");

                int count1 = 1;

                while (value2.next())
                {

                    homeThirdDown += Integer.parseInt(value2.getString(1).replaceAll("%", "").trim());

                    value2.next();

                    count1++;
                }

                homeThirdDown = homeThirdDown / count1;

                value2 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeRushAtt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeRushYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassAttOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassAtt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassCompOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassComp = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassYDSOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassIntOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassInt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FumblesOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeFumbles = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SackNumOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeSackNum = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SackYDSOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeSackYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PenYDSOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePenYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select TimePOSSOff from Stats2012 Where teamName = '" + homeTeam + "'");

                int count3 = 1;

                while (value2.next())
                {

                    homeTimeOfPoss += Integer.parseInt(value2.getString(1).replaceAll(":", "").trim());

                    value2.next();

                    count3++;
                }

                homeTimeOfPoss = homeTimeOfPoss / count3;

                value2 = stmt1.executeQuery("Select AVG(PuntAVGOff) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePuntAvg = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SCOREDEF) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppScore = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FIRSTDOWNDEF) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppFirstDown = value2.getInt(1);
                }

                int count8 = 0;

                value2 = stmt1.executeQuery("Select ThirdDownPCTDEF from Stats2012 Where teamName = '" + homeTeam + "'");

                while (value2.next())
                {

                    homeOppThirdDown += Integer.parseInt(value2.getString(1).replaceAll("%", "").trim());

                    value2.next();

                    count8++;
                }

                homeOppThirdDown = homeOppThirdDown / count8;

                value2 = stmt1.executeQuery("Select AVG(RUSHYDSDEF) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppRushYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PASSYDSDEF) from Stats2012 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppPassYards = value2.getInt(1);
                }

                value2.close();
            }

            /*
             * This is using stats from the 2013 NFL season. These stats are not
             * the full season just from the halfway point.
             */

            if (MainPanel.getAnswer() == 1)
            {
                Connection conn = DriverManager.getConnection("jdbc:derby:NFLStatsDatabase");
                Statement stmt1 = conn.createStatement();
                ResultSet value1;

                /*
                 * Away Team
                 * 2013 Stats
                 * Calculations
                 */

                value1 = stmt1.executeQuery("Select AVG(SCOREOFF) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayTotalScore = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FirstDownOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayFirstDown = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select ThirdDownPCTOff from Stats2013 Where teamName = '" + awayTeam + "'");

                int count2 = 1;

                while (value1.next())
                {

                    awayThirdDown += Integer.parseInt(value1.getString(1).replaceAll("%", "").trim());

                    value1.next();

                    count2++;
                }

                awayThirdDown = awayThirdDown / count2;

                value1 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushAtt = value1.getInt(1);
                }

                value1.close();

                value1 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushAtt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassAttOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassAtt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassCompOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassComp = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassYDSOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PassIntOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPassInt = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FumblesOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayFumbles = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SackNumOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awaySackNum = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SackYDSOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awaySackYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PenYDSOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPenYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select TimePOSSOff from Stats2013 Where teamName = '" + awayTeam + "'");

                int count4 = 1;

                while (value1.next())
                {

                    awayTimeOfPoss += Integer.parseInt(value1.getString(1).replaceAll(":", "").trim());

                    value1.next();

                    count4++;
                }

                awayTimeOfPoss = awayTimeOfPoss / count4;

                value1 = stmt1.executeQuery("Select AVG(PuntAVGOff) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayPuntAvg = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(SCOREDEF) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppScore = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(FIRSTDOWNDEF) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppFirstDown = value1.getInt(1);
                }

                int count7 = 0;

                value1 = stmt1.executeQuery("Select ThirdDownPCTDEF from Stats2013 Where teamName = '" + awayTeam + "'");

                while (value1.next())
                {

                    awayOppThirdDown += Integer.parseInt(value1.getString(1).replaceAll("%", "").trim());

                    value1.next();

                    count7++;
                }

                awayOppThirdDown = awayOppThirdDown / count7;

                value1 = stmt1.executeQuery("Select AVG(RUSHYDSDEF) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppRushYards = value1.getInt(1);
                }

                value1 = stmt1.executeQuery("Select AVG(PASSYDSDEF) from Stats2013 Where teamName = '" + awayTeam + "'");

                if (value1.next())
                {
                    awayOppPassYards = value1.getInt(1);
                }

                value1.close();

                /*
                 * Home Team
                 * 2013 Stats
                 * Calculations
                 */

                ResultSet value2 = stmt1.executeQuery("Select AVG(SCOREOFF) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeTotalScore = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FirstDownOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeFirstDown = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select ThirdDownPCTOff from Stats2013 Where teamName = '" + homeTeam + "'");

                int count1 = 1;

                while (value2.next())
                {

                    homeThirdDown += Integer.parseInt(value2.getString(1).replaceAll("%", "").trim());

                    value2.next();

                    count1++;
                }

                homeThirdDown = homeThirdDown / count1;

                value2 = stmt1.executeQuery("Select AVG(RushAttOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeRushAtt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(RushYDSOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeRushYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassAttOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassAtt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassCompOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassComp = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassYDSOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PassIntOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePassInt = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FumblesOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeFumbles = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SackNumOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeSackNum = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SackYDSOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeSackYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PenYDSOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePenYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select TimePOSSOff from Stats2013 Where teamName = '" + homeTeam + "'");

                int count3 = 1;

                while (value2.next())
                {

                    homeTimeOfPoss += Integer.parseInt(value2.getString(1).replaceAll(":", "").trim());

                    value2.next();

                    count3++;
                }

                homeTimeOfPoss = homeTimeOfPoss / count3;

                value2 = stmt1.executeQuery("Select AVG(PuntAVGOff) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homePuntAvg = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(SCOREDEF) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppScore = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(FIRSTDOWNDEF) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppFirstDown = value2.getInt(1);
                }

                int count5 = 0;

                value2 = stmt1.executeQuery("Select ThirdDownPCTDEF from Stats2013 Where teamName = '" + homeTeam + "'");

                while (value2.next())
                {

                    homeOppThirdDown += Integer.parseInt(value2.getString(1).replaceAll("%", "").trim());

                    value2.next();

                    count5++;
                }

                homeOppThirdDown = homeOppThirdDown / count5;

                value2 = stmt1.executeQuery("Select AVG(RUSHYDSDEF) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppRushYards = value2.getInt(1);
                }

                value2 = stmt1.executeQuery("Select AVG(PASSYDSDEF) from Stats2013 Where teamName = '" + homeTeam + "'");

                if (value2.next())
                {
                    homeOppPassYards = value2.getInt(1);
                }

                value2.close();
            }

            /*
             * This part of the calculateVictor method is adding points or 
             * subtracting points to the awayTeam and homeTeam based on the
             * average of their statistics.
             */
            if (awayTotalScore < homeTotalScore)
            {
                homeTeamTotalScore += 15;
            }

            if (awayTotalScore > homeTotalScore)
            {
                awayTeamTotalScore += 15;
            }

            if (awayTotalScore * 1.3 < homeTotalScore)
            {
                homeTeamTotalScore += 15;
            }

            if (homeTotalScore * 1.3 < awayTotalScore)
            {
                awayTeamTotalScore += 15;
            }

            if (awayFirstDown < homeFirstDown)
            {
                homeTeamTotalScore += 5;
            }

            if (awayFirstDown > homeFirstDown)
            {
                awayTeamTotalScore += 5;
            }

            if (awayThirdDown > homeThirdDown)
            {
                awayTeamTotalScore += 5;
            }

            if (awayThirdDown < homeThirdDown)
            {
                homeTeamTotalScore += 5;
            }

            if (awayRushYards > homeRushYards)
            {
                awayTeamTotalScore += 10;
            }
            
            if (awayRushYards < homeRushYards)
            {
                homeTeamTotalScore += 10;
            }
            
            if (awayRushYards / awayRushAtt > homeRushYards / homeRushAtt)
            {
                awayTeamTotalScore += 5;
            }

            if (awayRushYards / awayRushAtt < homeRushYards / homeRushAtt)
            {
                homeTeamTotalScore += 5;
            }

            if (awayPassYards > homePassYards)
            {
                awayTeamTotalScore += 10;
            }
            
            if (awayPassYards < homePassYards)
            {
                homeTeamTotalScore += 10;
            }
            
            if (awayPassYards / awayPassAtt > homePassYards / homePassAtt)
            {
                awayTeamTotalScore += 5;
            }

            if (awayPassYards / awayPassAtt < homePassYards / homePassAtt)
            {
                homeTeamTotalScore += 5;
            }

            if ((awayPassYards / awayPassAtt) * 1.5 < homePassYards / homePassAtt)
            {
                homeTeamTotalScore += 5;
            }

            if (homePassYards / homePassAtt * 1.5 < awayPassYards / awayPassAtt)
            {
                awayTeamTotalScore += 5;
            }

            if (awayPassComp > homePassComp)
            {
                awayTeamTotalScore += 5;
            }

            if (awayPassComp < homePassComp)
            {
                homeTeamTotalScore += 5;
            }

            if (awayPassComp * 1.5 < homePassComp)
            {
                homeTeamTotalScore += 5;
            }

            if (homePassComp * 1.5 < awayPassComp)
            {
                awayTeamTotalScore += 5;
            }

            if (awayPassInt > homePassInt)
            {
                awayTeamTotalScore -= -10;
            }

            if (awayPassInt < homePassInt)
            {
                homeTeamTotalScore -= -10;
            }

            if (awayFumbles > homeFumbles)
            {
                awayTeamTotalScore -= 10;
            }

            if (awayFumbles < homeFumbles)
            {
                homeTeamTotalScore -= 10;
            }

            if (awaySackNum > homeSackNum)
            {
                awayTeamTotalScore += 10;
            }

            if (awaySackNum < homeSackNum)
            {
                homeTeamTotalScore += 10;
            }

            if (awaySackYards > homeSackYards)
            {
                awayTeamTotalScore += 5;
            }

            if (awaySackYards < homeSackYards)
            {
                homeTeamTotalScore += 5;
            }

            if (awayPenYards > homePenYards)
            {
                awayTeamTotalScore -= 5;
            }

            if (awayPenYards < homePenYards)
            {
                homeTeamTotalScore -= 5;
            }

            if (awayTimeOfPoss > homeTimeOfPoss)
            {
                awayTeamTotalScore += 15;
            }

            if (awayTimeOfPoss < homeTimeOfPoss)
            {
                homeTeamTotalScore += 15;
            }

            if (awayPuntAvg > homePuntAvg)
            {
                awayTeamTotalScore += 5;
            }

            if (awayPuntAvg < homePuntAvg)
            {
                homeTeamTotalScore += 5;
            }

            if (awayOppScore > homeOppScore)
            {
                awayTeamTotalScore -= 15;
            }

            if (awayOppScore < homeOppScore)
            {
                homeTeamTotalScore -= 15;
            }

            if (awayOppFirstDown > homeOppFirstDown)
            {
                homeTeamTotalScore += 5;
            }

            if (awayOppFirstDown < homeOppFirstDown)
            {
                awayTeamTotalScore += 5;
            }

            if (awayOppThirdDown > homeOppThirdDown)
            {
                homeTeamTotalScore += 5;
            }

            if (awayOppThirdDown < homeOppThirdDown)
            {
                awayTeamTotalScore += 5;
            }

            if (awayOppRushYards > homeOppRushYards)
            {
                awayTeamTotalScore -= 10;
            }

            if (awayOppRushYards < homeOppRushYards)
            {
                homeTeamTotalScore -= 10;
            }

            if (awayOppPassYards > homeOppPassYards)
            {
                awayTeamTotalScore -= 10;
            }

            if (awayOppPassYards < homeOppPassYards)
            {
                homeTeamTotalScore -= 10;
            }


            /*
             * This part of the calculateVictor method is seeing which team had
             * the highest amount of points or if the game between them was a
             * tie and then displaying the victor and the stats used back to the
             * user of the application.
             */
            if (teams.getCount() == 0)
            {
                if (awayTeamTotalScore < homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextOne("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextOne("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore > homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextOne("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextOne("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore == homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextOne("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextOne("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2013 NFL Stats.");
                    }
                }
            }

            if (teams.getCount() == 1)
            {
                if (awayTeamTotalScore < homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextTwo("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextTwo("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore > homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextTwo("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextTwo("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore == homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextTwo("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextTwo("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2013 NFL Stats.");
                    }
                }
            }

            if (teams.getCount() == 2)
            {
                if (awayTeamTotalScore < homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextThree("The home team: " + homeTeam + " won the game against the away team:" + awayTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextThree("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore > homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextThree("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextThree("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore == homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextThree("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextThree("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2013 NFL Stats.");
                    }
                }
            }

            if (teams.getCount() == 3)
            {
                if (awayTeamTotalScore < homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFour("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFour("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore > homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFour("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFour("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore == homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFour("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFour("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2013 NFL Stats.");
                    }
                }
            }

            if (teams.getCount() == 4)
            {
                if (awayTeamTotalScore < homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFive("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFive("The home team: " + homeTeam + " won the game against the away team: " + awayTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore > homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFive("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFive("The away team: " + awayTeam + " won the game against the home team: " + homeTeam + " using the 2013 NFL Stats.");
                    }
                }

                if (awayTeamTotalScore == homeTeamTotalScore)
                {
                    if (MainPanel.getAnswer() == 0)
                    {
                        teams.setResultTextFive("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + "  using the 2012 NFL Stats.");
                    }

                    if (MainPanel.getAnswer() == 1)
                    {
                        teams.setResultTextFive("This game is a tie between the away team: " + awayTeam + " and the home team:  " + homeTeam + " the using the 2013 NFL Stats.");
                    }
                }
            }
        } catch (Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR!", 1);
        }
    }
}
